import React from 'react';

import {
  StyleSheet, View, Text, TextInput, TouchableOpacity,
} from 'react-native';
import { Icon } from 'native-base';
import Theme from '../native-base-theme/variables/commonColor';

let inputValue = '';
const _onChangeText = (v) => {
  inputValue = v;
};

const _onSearch = (search) => {
  search(inputValue);
};

export default ({
  placeholder, search,
}) => (
  <View style={styles.root_container}>
    <View style={styles.circle_container}>
      <Icon name="ios-search" style={{ fontSize: 24 }} />
      <TextInput
        onChangeText={_onChangeText}
        style={styles.text_input}
        underlineColorAndroid="transparent"
        placeholder={placeholder}
        defaultValue=""
        onSubmitEditing={() => _onSearch(search)}
      />
    </View>
    <TouchableOpacity
      style={{ padding: 10 }}
      onPress={() => _onSearch(search)}
    >
      <Text style={{ color: 'white' }}>搜索</Text>
    </TouchableOpacity>
  </View>
);

const styles = StyleSheet.create({
  root_container: {
    paddingTop: 10,
    paddingBottom: 10,
    backgroundColor: Theme.myPrimary,
    flexDirection: 'row',
    alignItems: 'center',
  },
  circle_container: {
    flex: 1,
    padding: 5,
    backgroundColor: '#DEE1E6',
    borderRadius: 10,
    flexDirection: 'row',
    alignItems: 'center',
  },
  text_input: {
    flex: 1,
    marginLeft: 5,
    padding: 0,
  },
});
